#ifndef QSFMLCANVAS_H
#define QSFMLCANVAS_H

#include <QWidget>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <QTimer>
#include <QResizeEvent>

class QSFMLCanvas : public QWidget, public sf::RenderWindow
{
    Q_OBJECT
public:
    explicit QSFMLCanvas(QWidget *parent);
    virtual ~QSFMLCanvas();

    void         SetMaxSize(sf::Vector2f s) { _maxSize = s;      }
    sf::Vector2f GetMaxSize(void) const     { return (_maxSize); }
    
signals:
    
public slots:

private:
    virtual QPaintEngine* paintEngine(void) const;
    virtual void showEvent(QShowEvent *);
    virtual void paintEvent(QPaintEvent *);
    virtual void resizeEvent(QResizeEvent *);

protected:
    virtual void OnInit(void);
    virtual void OnUpdate(void);
    virtual void mousePressEvent(QMouseEvent *);
    virtual void mouseMoveEvent(QMouseEvent *);
    virtual void mouseReleaseEvent(QMouseEvent *);

    QPoint       GetAbsolutePosFromClick(const QMouseEvent*) const;

private:
    QTimer       _timer;
    bool         _initialized;
    sf::Vector2f _maxSize;
    bool         _isMoving;
    sf::Vector2f _movingLastPos;
};

#endif // QSFMLCANVAS_H
